package algotrader;

import java.io.FileInputStream;

import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;

import quickfix.DefaultMessageFactory;
import quickfix.FileStoreFactory;
import quickfix.Initiator;
import quickfix.MessageFactory;
import quickfix.MessageStoreFactory;
import quickfix.ScreenLogFactory;
import quickfix.SessionSettings;
import quickfix.SocketInitiator;

import algotrader.book.BookManager;
import algotrader.gui.BMFTradingBorderFrame;
import algotrader.gui.LoginPanel;
import algotrader.model.Operador;

public class App {
	
//	static {
//		System.loadLibrary("libs/quickfix_jni");
//	}
	
	public static Operador o;
	private BMFTradingBorderFrame frame;
	private BookManager bookManager;
	private OperadorPregao operadorPregao;
	
	public App() {
		try {
			String fileName = "mds.cfg";
			SessionSettings settings = new SessionSettings(new FileInputStream(
					fileName));

			MessageStoreFactory storeFactory = new FileStoreFactory(settings);
			MessageFactory messageFactory = new DefaultMessageFactory();
			ScreenLogFactory screenLog = new ScreenLogFactory(true, true, true);
			bookManager = new BookManager();
			FixApplication fixApp = new FixApplication(bookManager);
			bookManager.setFixApplication(fixApp);
			Initiator acceptor = new SocketInitiator(fixApp, storeFactory,
					settings, screenLog, messageFactory);
			operadorPregao = new OperadorPregao(fixApp);
			frame = new BMFTradingBorderFrame(bookManager,o,operadorPregao);
			fixApp.addLogonObserver(frame);
			frame.setTitle("BMF Trading Border");
			frame.setVisible(true);
			acceptor.start();
			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

    public static void main( String[] args )
    {
    	try {
			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
		} catch (Exception e) {
			
			e.printStackTrace();
		}  
		JFrame.setDefaultLookAndFeelDecorated(true);
		
//		JDialog dialog = new JDialog();
//		LoginPanel loginPanel = new LoginPanel();
//    	dialog.getContentPane().add(loginPanel);
//    	dialog.setTitle("Algotrader");
//    	dialog.setModal(true);
//    	dialog.pack();
//    	dialog.setLocationRelativeTo(null);
//    	dialog.setVisible(true);
//    	o = loginPanel.getOperdor();
//    	System.out.println(o);
    	
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				new App();
			}
		});
    	
    }
}
